package grex.genes;

import WekaModels.GrexLinearRegression;
import grex.BNFException;
import grex.ErrorManager;
import grex.Prediction;
import grex.PredictionContainer;

import java.text.NumberFormat;

public class WMregPred extends Gene implements ITerminal {

    private static final int NROFCILDREN = 0;
    private int varNr = -1;
    private double k = 0,  m = 0;//Y=kx+m
    private int size = 0;
    private Double prob = new Double(-1);
    private Double lowerProb = new Double(0.0);
    private int lowerCount = 0,  probCount = 0;
    GrexLinearRegression model;

    public WMregPred() throws BNFException {
        super(NROFCILDREN);
    }

    public synchronized void execute(Gene parent, PredictionContainer data, int mode) throws GeneException {
        this.parent = parent;
        if(data.values().isEmpty())
            return;
        
        if (mode == Gene.TRAIN_MODE|| mode == Gene.OPTIMIZE_MODE) {
            model = new GrexLinearRegression(environment);
            model.train(data);
            size = data.values().size();

            prob = new Double(0);
            lowerProb = new Double(0);

            lowerCount = 0;
            probCount = 0;
        }
        model.execute(data);
    }



    public void setVarNr(int varNr) {
        this.varNr = varNr;
    }

    public int getVarNr() {
        return varNr;
    }



    public Object clone() {
        
        WMregPred reg;
        try {
            reg = new WMregPred();
            reg.setVarNr(varNr);
            reg.setOptions(ops);
            reg.setEnvironment(environment);
            reg.model = model;
            reg.setParent(parent);
            reg.size = size;
            reg.lowerProb=lowerProb;
            reg.prob=prob;
        } catch (grex.BNFException e) {
            ErrorManager.getInstance().reportError(e);
            return null;
        }
        return reg;
    }

    public synchronized String toString() {
            if(model == null)
                return "intron";
            return model.toString();
    }

    public double getProb() {
        return prob;
    }

    public int getCount() {
        return size;
    }

    public double getLowProb() {
        return lowerProb;
    }
}
